package com.kongchengji.spider.util;

import com.kongchengji.spider.station.domain.PictureModelDO;
import com.kongchengji.spider.station.domain.SourceStationDO;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class ManageTypeListUtil {
    /**
     * 处理第一种情况，不需要再图集类型中提取标题的情况
     * @param typeList 存储type的集合
     * @param pictureModelDO 传入实例，初始化type和sourceStationDOS成员
     */
    public static void manageType1(List<String> typeList,String title, PictureModelDO pictureModelDO){
        List<SourceStationDO> sourceStationDOS = new ArrayList<>();
        int current = 0;
        for(String type : typeList){
            //如果typeList大小为1则不用判断
            if(typeList.size() != 1){
                //判断图片导航中存在标题吗,存在则排除该导航
                double similarity= CosineUtil.getSimilarity(type,title);
                if(similarity > 0.86){
                    continue;
                }
            }
            SourceStationDO sourceStationDO = new SourceStationDO();
            sourceStationDO.setName(StringUtils.trim(type));
            sourceStationDOS.add(sourceStationDO);
        }
        pictureModelDO.setSourceStationDOS(sourceStationDOS);
    }

    /**
     * 处理第二种情况，需要再图集类型中提取标题的情况
     * @param typeList 存储type的集合
     * @param pictureModelDO 传入实例，初始化type和sourceStationDOS成员
     */
    public static void manageType2(List<String> typeList, PictureModelDO pictureModelDO){

        List<SourceStationDO> sourceStationDOS = new ArrayList<>();
        int cursor = 0;
        for(String type: typeList){
            cursor++;
            //最后一个统一处理
            if(cursor == typeList.size() ){
                //最后一个是标题
                pictureModelDO.setTitle(StringUtils.trim(type));
                continue;
            }
            SourceStationDO sourceStationDO = new SourceStationDO();
            sourceStationDO.setName(StringUtils.trim(type));
            sourceStationDOS.add(sourceStationDO);
        }
        pictureModelDO.setSourceStationDOS(sourceStationDOS);
    }
}
